package com.ss.project.xia17user.common.mail;

import lombok.extern.slf4j.Slf4j;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;


/**
 * 邮件发送
 * @author xia17
 * @date 2020/11/24 17:20
 */
@Slf4j
public class MailSender {

    /** 是否启用 */
    private boolean enabled;
    /** 发送邮件的工具类 */
    private JavaMailSender javaMailSender;

    /**
     * 发送邮件
     * @param to
     * @param subject
     * @param content
     */
    public void sendMail(String to , String subject , String content){
        SimpleMailMessage message = new SimpleMailMessage();
        message.setFrom("1320442120@qq.com");
        message.setTo(to);
        message.setSubject(subject);
        message.setText(content);
        sendEmail(message);
    }

    private void sendEmail(SimpleMailMessage ... messages){
        javaMailSender.send(messages);
    }


    public synchronized MailSender setEnabled(boolean enabled){
        this.enabled = enabled;
        return this;
    }

    public MailSender setJavaMailSender(JavaMailSender javaMailSender){
        this.javaMailSender = javaMailSender;
        return this;
    }



}
